package com.hand.demo.app.service.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hand.demo.domain.entity.XzyExample;
import com.hand.demo.domain.repository.XzyExampleRepository;
import org.hzero.boot.imported.app.service.IDoImportService;
import org.hzero.boot.imported.infra.validator.annotation.ImportService;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.IOException;

// 和平台模板代码一致，继承IDoImportService接口
@ImportService(templateCode = "CLIENT_IMPORT_YIGE")
public class XzyImportService implements IDoImportService {
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private XzyExampleRepository repository;
    @Override
    public Boolean doImport(String data) {
        XzyExample user;
        try {
            user = objectMapper.readValue(data, XzyExample.class);
        } catch (IOException e) {
            // 失败
            return false;
        }
        if(user.getName().equals("腚真")) {
            repository.insertSelective(user);
        }

        // 成功
        return true;
    }
}